package object;

import java.awt.Color;
import java.util.ArrayList;

import util.Settings;

import networkInterface.NetworkInterfaceBase;

import logging.Logger;

public class Node {
	private ArrayList<NetworkInterfaceBase> interfaces = new ArrayList<NetworkInterfaceBase>();
	
	private Point point;
	
	public Color color = Settings.getInstance().getFrontColor();
	
	public Node(){}
	
	public Node(int x, int y){
		Logger.getInstance().log(Logger.TRACE, "Node Constructor x:" + x + " y:"+ y);
		point = new Point(x,y);
	}
//	public void addConnection(Connection c){
//		//TODO: if not already connected
//		connections.add(c);
//	}
	
	public boolean isDirectlyConnected(Node n){
		for(NetworkInterfaceBase i : interfaces){
			for(Connection c : i.getConnections()){
				if(c.isMember(n))
					return true;
			}
		}
		return false;
	}
	
	//TODO: isConnected traversal
	
	public ArrayList<Connection> getConnections() {
		ArrayList<Connection> connections = new ArrayList<Connection>();
		for(NetworkInterfaceBase i : interfaces){
			connections.addAll(i.getConnections());
		}
		return connections;
	}

	public int getX() throws NullPointerException{
		return point.getX();
	}
	
	public int getY() throws NullPointerException{
		return point.getY();
	}
	
	public ArrayList<NetworkInterfaceBase> getInterfaces(){
		return interfaces;
	}
	
	public double getLength(Node n){
		return Math.sqrt((getX() - n.getX()) * (getX() - n.getX()) + (getY() - n.getY()) * (getY() - n.getY()));
	}
	public void addNetworkInterface(NetworkInterfaceBase ni){
		interfaces.add(ni);
	}
	
	public ArrayList<Node> getDirectlyConnected(){
		ArrayList<Node> ret = new ArrayList<Node>();
		for(NetworkInterfaceBase n : interfaces){
			ret.addAll(n.getDirectlyConnected());
		}
		return ret;
	}
	
	
}
